#include "linuxheader.h"
#include <workflow/MySQLUtil.h>
#include <workflow/MySQLResult.h>
static WFFacilities::WaitGroup waitGrop(1);

void sighandler(int num)
{
    fprintf(stderr,"grop is wait!");
    waitGrop.done();
}
void callback(WFMySQLTask*mysqlTask)
{
//检查连接错误;
if(mysqlTask->get_state()!=WFT_STATE_SUCCESS)
{
fprintf(stderr,"error:%s\n",WFGlobal::get_error_string(mysqlTask->get_state(),mysqlTask->get_error()));

}
protocol::MySQLResponse *resp = mysqlTask->get_resp();
protocol::MySQLRequest *req = mysqlTask->get_req();
protocol::MySQLResultCursor cursor(resp);//迭代器简单回应的报文；
//检查语法出错哪一行；
if(resp->get_packet_type()==MYSQL_PACKET_ERROR)
{
    fprintf(stderr,"error_code = %d msg =%s\n",resp->get_error_code(),resp->get_error_msg().c_str());
}
if(cursor.get_cursor_status()==MYSQL_STATUS_OK)
{
    //写执行，执行成功；
    fprintf(stderr,"OK. %llu rows affectes. %d warnings. insert_id = %llu.\n",
                   cursor.get_affected_rows(),cursor.get_warnings(),cursor.get_insert_id());
}

}



int main()
{
    signal(SIGINT,sighandler);
    //创建一个MySQL的基础工作加回调函数；
    auto mysqlTask = WFTaskFactory::create_mysql_task("mysql://root:123@127.0.0.1:3306",0,callback);
    std::string sql = "insert into cloudisk.tn_usr_tokrn(usr_name,usr_token)values ('test5','abc');";
   auto req = mysqlTask->get_req();
   req->set_query(sql);
   mysqlTask->start();
    waitGrop.wait();
    return 0;
}